
using DataSystem;
using FairyGUI;
using FairyGUI.Utils;
using TerrainSystem;
using UnityEngine;
using Utility.PoolSystem;

namespace UIPackage_Main
{
	public partial class UI_Item_Handful
	{
		private TileGroupSetting _tileGroupSetting;
		private UPRef<TileGroup> _upRef;
		private GoWrapper _goWrapper;
		partial void OnCreate ()
		{
			_goWrapper = new GoWrapper();
			onClick.Add (OnClick);
		}

		private void OnClick ()
		{
			Main.Game.Construction.Build_End ();
			Main.Game.Construction.Build_Start (_tileGroupSetting);
		}

		public void UpdateUI (TileGroupSetting tileGroupSetting)
		{
			_tileGroupSetting = tileGroupSetting;
			_upRef = TileGroup.Spawn (tileGroupSetting);

			var gObj = _upRef.GameObject;
			var transform = gObj.transform;
			transform.localPosition = new Vector3 (100, -60, 0); //set z to far from UICamera is important!
			transform.localScale = new Vector3 (60, 60, 60);
			transform.localEulerAngles = new Vector3 (-90, 0, 0);
			_goWrapper.SetWrapTarget (gObj, true);
			m_Graph_ModelHolder.SetNativeObject (_goWrapper);
		}
	}
}